<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>扫码开锁</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/zy_common.css"/>
    <link rel="stylesheet" href="../css/zy_base.css"/>
</head>
<body>
    <div class="ptb30 col9 font13 bw plr24">
        <p class="mb20 col3 font15" id="macno">设备编号：4564654665465</p>
        <p class="mb10 color2" id="inventory">库存：52</p>
        <p class="mb10" id="addr">地址：广东省东莞市南城区高盛科技园</p>
    </div>
    <div class="bw mt20 plr24 flex_a">
        <span class="col3 font15">修改库存：</span>
        <input type="number" placeholder="请输入库存" class="h100 col9 font15 flex1" oninput="this.value = this.value.replace(/\D/g,'')" id="num">
    </div>
    <div class="mt20 bw plr24 pt30">
        <p class="col3 font15">开锁目的</p>
        <div class="flex_a">
            <label class="flex_a ptb30 mr70">
                <input type="radio" name="radio" hidden class="radioBox" value="1" checked>
                <span class="roudBox border"></span>
                <span class="font15 col3 ml20">补货</span>
            </label>
            <label class="flex_a ptb30 mr70">
                <input type="radio" name="radio" hidden class="radioBox" value="2">
                <span class="roudBox border"></span>
                <span class="font15 col3 ml20">机器故障</span>
            </label>
            <label class="flex_a ptb30">
                <input type="radio" name="radio" hidden class="radioBox" value="3">
                <span class="roudBox border"></span>
                <span class="font15 col3 ml20">其他</span>
            </label>
        </div>
        <div>
            <input type="text" placeholder="请输入开锁目的" class="h100 font15 col9 w100" id="reason" style="display: none;">
        </div>
    </div>
    <div class="confirm" style="margin-top: .6rem">保存</div>
</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script>
    var _value=1,onOff=0,addressDetail,deviceId;
    $(function () {

        $('#macno').text('设备编号：'+getUrlParam('macno'));
        dlctipbox.loading('请稍后');
        dlc_request('/api/device/getDeviceList',{id:getLocalData('fd_id'),type:2,deviceNo:getUrlParam('macno')},function (res) {
            dlctipbox.clear();
            console.log(res);
            if(res.code==1){
                var res = res.data[0];
                $('#addr').text('地址：'+res.addressDetail);
                $('#inventory').text('库存：'+res.inventory);
                addressDetail = res.addressDetail;//地址id
                deviceId=res.deviceId;
            }else{
                dlctipbox.show(res.msg);
            }
        })
        $('.radioBox').change(function () {
            _value = $('.radioBox:checked').val();
           if(_value==3){
               $('#reason').parent().addClass('bdt');
                $('#reason').show();
           }else{
               $('#reason').parent().removeClass('bdt');
               $('#reason').hide();
           }
        });
        //确定
        $('.confirm').click(function () {
            var num = $('#num').val();
            var reason = $('#reason').val();
            var status = $('.radioBox:checked').val();
            console.log(status);

            if(_value==3){
                if(isNull(reason)){
                    dlctipbox.show('请输入开锁目的');
                    return false
                }
            }else if(_value==1){
                reason = '补货';
            }else{
                reason = '机器故障';
            }
            var data ={
                maintainerId:getLocalData('fd_id'),
                deviceNo:getUrlParam('macno'),
                addressId:addressDetail,
                purpose:reason,
                deviceId:deviceId
            };
            //有填库存时
            if(num){
                data.inventory=num;
            }

            if(onOff)return false;
            onOff=1;
            dlctipbox.loading('请稍后');
            dlc_request('/api/devicelog/saveDevicelog',data,function (res) {
                dlctipbox.clear();
                console.log(res);
                if(res.code==1){
                    dlctipbox.alert('保存成功',function (flag) {
                        if(flag==1){
                            history.go(-1);
                        }
                    })
                }else{
                    onOff=0;
                    dlctipbox.show(res.msg);
                }
            })

        })
    })
</script>